package one.bugu.android.demon.ui.activity.snatch;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.juefeng.android.framework.view.annotation.LKContentView;
import com.juefeng.android.framework.view.annotation.LKInjectView;

import java.util.ArrayList;
import java.util.List;

import one.bugu.android.demon.R;
import one.bugu.android.demon.common.MyBaseActivity;
import one.bugu.android.demon.ui.adapter.snatch.FragmentAdapter;
import one.bugu.android.demon.ui.fragment.snatch.SnatchRecordFragment;
import one.bugu.android.demon.ui.widget.BaseTopBarView;
import one.bugu.android.demon.util.StatusBarUtils;

/**
 * Description SnatchRecordActivity 夺宝记录
 *
 * @author liuxin
 * @date 2018/10/27 11:47
 */
@LKContentView(R.layout.activity_snatch_record)
public class SnatchRecordActivity extends MyBaseActivity implements View.OnClickListener {

    @LKInjectView(R.id.btbv_snatch_record)
    private BaseTopBarView btbv_snatch_record;

    @LKInjectView(R.id.rl_under_way)
    private RelativeLayout rl_under_way;

    @LKInjectView(R.id.rl_end)
    private RelativeLayout rl_end;

    @LKInjectView(R.id.rl_record)
    private RelativeLayout rl_record;

    @LKInjectView(R.id.tv_under_way)
    private TextView tv_under_way;

    @LKInjectView(R.id.tv_end)
    private TextView tv_end;

    @LKInjectView(R.id.tv_record)
    private TextView tv_record;

    @LKInjectView(R.id.view_under_way)
    private View view_under_way;

    @LKInjectView(R.id.view_end)
    private View view_end;

    @LKInjectView(R.id.view_record)
    private View view_record;

    @LKInjectView(R.id.vp_record)
    private ViewPager vp_record;

    public static final int UNDER_WAY = 0;
    public static final int END = 1;
    public static final int RECORD = 2;

    @Override
    protected void initView() {
        super.initView();
        //设置状态栏
        StatusBarUtils.getInstance().setStatusBar("#FFFFFF", this, btbv_snatch_record, false);
        //默认显示抢购中列表
        setTab(UNDER_WAY);
        //添加页面展示fragment
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(SnatchRecordFragment.newInstance(SnatchRecordFragment.UNDER_WAY));
        fragmentList.add(SnatchRecordFragment.newInstance(SnatchRecordFragment.END));
        fragmentList.add(SnatchRecordFragment.newInstance(SnatchRecordFragment.RECORD));
        //viewpager适配器初始化
        FragmentAdapter mAdater = new FragmentAdapter(getSupportFragmentManager(), fragmentList);
        vp_record.setAdapter(mAdater);

        vp_record.setOffscreenPageLimit(fragmentList.size());
    }

    @Override
    protected void initData() {
        super.initData();

    }

    @Override
    protected void initEvent() {
        super.initEvent();

        rl_under_way.setOnClickListener(this);
        rl_end.setOnClickListener(this);
        rl_record.setOnClickListener(this);

        btbv_snatch_record.setEventInterface(new BaseTopBarView.EventInterface() {
            @Override
            public void leftOnClick() {
                finish();
            }

            @Override
            public void leftCloseClick() {

            }

            @Override
            public void rightOnClick() {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_under_way:
                setTab(UNDER_WAY);
                break;
            case R.id.rl_end:
                setTab(END);
                break;
            case R.id.rl_record:
                setTab(RECORD);
                break;
            default:
                break;
        }
    }

    /**
     * 设置tab按钮状态
     *
     * @param tab
     */
    private void setTab(int tab) {
        tv_under_way.setSelected(tab == UNDER_WAY);
        tv_end.setSelected(tab == END);
        tv_record.setSelected(tab == RECORD);

        view_under_way.setVisibility(tab == UNDER_WAY ? View.VISIBLE : View.GONE);
        view_end.setVisibility(tab == END ? View.VISIBLE : View.GONE);
        view_record.setVisibility(tab == RECORD ? View.VISIBLE : View.GONE);

        //设置页面展示
        vp_record.setCurrentItem(tab);
    }
}
